#ifndef PATH_PLANNER_H
#define PATH_PLANNER_H

#include "GraphEdge.h"
#include "GraphNode.h"
#include "GraphTypes.h"
#include "SearchAlgorithms.h"
#include "Vector2D.h"
#include <iostream>
#include "Path.h"
#include "TimeSlicedGraphAlgorithms.h"

using namespace std;

class MovingEntity;

class PathPlanner
{
private:
	enum {no_closest_node_found = -1};
	typedef SparseGraph<NavGraphNode<void*>, GraphEdge> NavGraph;
	list<Vector2D> WaypointList;
	
	// A pointer to the owner of this instance
	MovingEntity* m_pOwner;

	// A pointer to the nav graph
	NavGraph* m_pNavGraph;
	Vector2D m_vDestinationPos;

	Graph_SearchTimeSliced<GraphEdge>* m_pCurrentSearch;
	

	void SmoothEdges(Path& path);
	void GetReadyForNewSearch();

public:

	PathPlanner(MovingEntity* owner);

	bool		RequestPathToPosition(Vector2D TargetPos);
	
	Path		GetPath();

	int			CycleOnce()const;

	Vector2D	GetDestination()const{return m_vDestinationPos;}
	int GetClosestLandNode(Vector2D ToPosition, int idx);
	void		SetDestination(Vector2D dest) {m_vDestinationPos = dest;}


	int GetClosestNodeToPosition(Vector2D Pos);
};


#endif